<?php

require_once __DIR__ ."/../inc/constantes.php"; 
require_once __DIR__ ."/../vendor/autoload.php"; 
require_once __DIR__ ."/../inc/functions.php"; 
require_once __DIR__ ."/../inc/db.php";

/**
 * Description of app
 *
 * @author Guy
 */
class App {
    
    protected $js;
    protected $css;
    protected $title;
    protected $db;
    protected $persistance;
    
    public function __construct($title) {        
        //Class Loader
        spl_autoload_register(function($class)
        {
            $tries = array(
                __DIR__ ."/../indexation/",
                __DIR__ ."/../model/",
                __DIR__ ."/../evaluateur/"
            );
            
            foreach($tries as $try)
            {
                $file = $try.$class.".php";
                if(file_exists($file))
                {
                    include $file;
                }
            }
        });
        
        $this->title            = $title;
        $this->js               = array();
        $this->css              = array();       
        $this->db               = getDB(); //Fournie dans inc/db.php
        $this->persistance      = new Persistance($this->db);           
    }
    
    public function header()
    {
        require_once __DIR__ ."/../web/tpl/header.php";
        displayHeader($this);
    }
    
    public function footer()
    {
        require_once __DIR__ ."/../web/tpl/footer.php";
        displayFooter($this);
    }
    
    public function addJs($path)
    {
        $this->js[] = $path;
        
        return $this;
    }
    
    public function addCss($path)
    {
        $this->css[] = $path;
        
        return $this;
    }
    
    public function getJs() {
        return $this->js;
    }

    public function getCss() {
        return $this->css;
    }

    public function getTitle() {
        return $this->title;
    }

    /**
     * 
     * @return PDO
     */
    public function getDb() {
        return $this->db;
    }

    public function setJs($js) {
        $this->js = $js;
        return $this;
    }

    public function setCss($css) {
        $this->css = $css;
        return $this;
    }

    public function setTitle($title) {
        $this->title = $title;
        return $this;
    }
    
    public function setDb($db) {
        $this->db = $db;
        return $this;
    }

    /**
     * 
     * @return Persistance
     */
    public function getPersistance() {
        return $this->persistance;
    }

    public function setPersistance($persistance) {
        $this->persistance = $persistance;
        return $this;
    }
}
